<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('修改质检单明细')" />

<body>

<div class="group-button" id="toolbar">
    <a class="layui-btn layui-btn-sm layui-btn-normal eidtBtn">
        <i class="layui-icon">&#x1005;</i>
    </a>
</div>
<section class="panel panel-padding layui-card-body">
    <div class="pro">
        <table id="table" class="table text-nowrap"></table>
    </div>
    <input type="hidden" class="layui-input" th:value="${sszjdid}" id="sszjdid"/>
</section>

</body>
<div th:include="public/public_js::public_js"></div>

<script th:inline="javascript">
    $(function () {
    })

</script>

<style type="text/css">

</style>
<script>

    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent = {
            "click .layui-btn-primary": function (e, value, row, index) {
                /*这里激活状态那个按钮用不到，啥都不需要写，只读*/
            },
        }
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;

        $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            uniqueId:"id",
            pagination: true,
            url: '/wmsqualityinspectionlistdetailed/list/'+$("#sszjdid").val(),
            columns: [{
                field: '',
                checkbox: true
            },{
                field: 'idex',
                title: 'idex',
                visible:false
            },{
                field: 'nuber',
                title: 'nuber',
                visible:false
            },{
                field: 'zjsf',
                title: '质检方式'
            },{
                field: 'goodsbh',
                title: '货品编号'
            },{
                field: 'goodsmc',
                title: '货品名称'
            },{
                field: 'bzmc',
                title: '包装名称'
            },{
                field: 'dwmc',
                title: '单位名称'
            },{
                field: 'shsl',
                title: '收货数量'
            },{
                field: 'ypsl',
                title: '样品数鲁'
            },{
                field: 'yjsl',
                title: '应检数量',
                formatter: operateFormatterNumber
            },{
                field: 'show_zt',
                title: '质检状态'
            }, {
                field: 'pc',
                title: '批次'
            },{
                field: 'scrq',
                title: '生产日期'
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });


        function operateFormatterNumber (value,row,index) {
            return [
                '<input type="text"  id="dongjieNumber'+index+'" onblur="changett('+index+','+row.yjsl+',\''+row.id+'\')"  value="'+ value +'"/>',
            ].join('')
        }

        $(".eidtBtn").on('click',function () {
            var rows = $("#table").bootstrapTable('getSelections');
            var array=[];
            var pass={};
            for(var i=0;i<rows.length;i++){
                pass={};
                pass.OldNumber_shsl=rows[i].shsl;
                pass.id=rows[i].id;
                pass.yjsl=rows[i].yjsl;
                pass.asnmxid=rows[i].asnmxid;
                pass.sszjdid=rows[i].sszjdid;
                array.push(pass);
            }
            if(rows.length == 0){
                layer.msg("请选择一条进行修改");
            }else{

                zzpUtils.action({
                    url:"/wmsqualityinspectionlistdetailed/editZjd",
                    data:JSON.stringify(array),
                    success:function (data) {
                        setTimeout(function(){
                            if(data.type=='success'){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                top.layer.msg(data.title);
                            }else{
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                top.layer.msg(data.message);
                            }
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                });
            }
        })

    });

    function changett(index,sl,id){
        var dongjiedata = $('#dongjieNumber'+index).val();
        if (/^\d+$/.test(dongjiedata)) {
            if (parseInt(dongjiedata) <= parseInt(sl)) {
                $('#dongjieNumber'+index).val(dongjiedata);
            }else{
                $('#dongjieNumber'+index).val(sl);
            }
        }
    }

</script>
</html>
